'use strict';

const { Controller } = require('egg');
const Result = require('../util/result');

class OrderMasterController extends Controller {
  async index() {
    const condi = { limit: Result.toInt(this.ctx.query.limit) };
    const response = await this.ctx.service.orderMaster.index(condi);
    this.ctx.body = response;
  }

  async create() {
    const data = this.ctx.request.body;
    const response = await this.ctx.service.orderMaster.create(data);
    this.ctx.body = response;
  }

  async show() {
    const id = this.ctx.params.id;
    const response = await this.ctx.service.orderMaster.show(id);
    this.ctx.body = response;
  }

  async update() {
    const id = this.ctx.params.id;
    const data = this.ctx.request.body;
    const response = await this.ctx.service.orderMaster.update(id, data);
    this.ctx.body = response;
  }

  async destroy() {
    const id = this.ctx.params.id;
    const response = await this.ctx.service.orderMaster.destroy(id);
    this.ctx.body = response;
  }

  async findByUid() {
    const query = {
      limit: Result.toInt(this.ctx.query.limit),
      uid: this.ctx.query.uid,
    };
    const response = await this.ctx.service.orderMaster.findAllOrder(query);
    this.ctx.body = response;
  }

  async findByStatus() {
    const query = {
      limit: Result.toInt(this.ctx.query.limit),
      pay_status: this.ctx.query.status,
    };
    const response = await this.ctx.service.orderMaster.findByStatus(query);
    this.ctx.body = response;
  }
}

module.exports = OrderMasterController;
